// CompareTwoValue.h

#ifndef _CompareTwoValue_h_
#define _CompareTwoValue_h_

#if _MSC_VER > 1000
	#pragma once
#endif

#define COMPARE_OPER_TMPL(member, lessRet, greatRet)	\
	do {												\
		if(member < r.member)							\
			return (lessRet);							\
		if(r.member < member)							\
			return (greatRet);							\
	} while(0)

template<typename TYPE_L, typename TYPE_R>
struct CompareTwoValueTmpl
{
	const TYPE_L& l;
	const TYPE_R& r;
	CompareTwoValueTmpl(const TYPE_L& lv, const TYPE_R& rv)
		: l(lv), r(rv) {}
	int Compare() const
	{
		if(l < r)
			return -1;
		if(r < l)
			return 1;
		return 0;
	}
};
template<typename TYPE_L, typename TYPE_R>
inline int CompareTwoValue(const TYPE_L& l, const TYPE_R& r)
	{	return CompareTwoValueTmpl<TYPE_L, TYPE_R>(l, r).Compare();	}

template<typename Container>
int ContainerCompare(const Container& left, const Container& right)
{
	if(&left == &right)
		return 0;

	typename Container::const_iterator itL = left.begin();
	typename Container::const_iterator itR = right.begin();
	for(; itL!=left.end() && itR!=right.end(); ++itL, ++itR)
	{
		int cmp = CompareTwoValue(*itL, *itR);
		if(0 != cmp)
			return cmp;
	}

	if(itL==left.end() && itR==right.end())
		return 0;
	return itL==left.end() ? -1 : 1;
}

#endif	// #ifndef _CompareTwoValue_h_
